<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>9sku的算法升级</title>
</head>

<body>

</body>
<script>
  "use strict"; {
    const result = {
      'a-b-c': { remain: 10, price: 1000 },
      'a-B-c': { remain: 2, price: 1100 },
      'A-B-C': { remain: 10, price: 1000 }
    }
    const items = [['a', 'A'], ['b', 'B'], ['c', 'C']]
    const data = {}

    function getRemainByKey(selected) {
      const key = selected.join('-')
      if (typeof data[key] !== 'undefined') {
        return data[key]
      }

      if (selected.length === items.length) {
        return result[key] ? data[key] = result[key].remain : data[key] = 0
      }

      let remain = 0
      let tempSelected = []

      for (let i = 0; i < items.length; i++) {
        const exist = items[i].find(_item => _item === selected[0])
        if (exist && selected.length > 0) {
          tempSelected.push(selected.shift())
        } else {
          items[i].forEach(_item => {
            remain += getRemainByKey(tempSelected.concat(_item, selected))
          })
          break
        }
      }
      return data[key] = remain
    }

    console.log(getRemainByKey(['a']))
  };
</script>

</html>